package Views;

import Models.Vare;
import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;

public class VareTableModel extends DefaultTableModel
{
	private ArrayList<Vare> varer;

	public VareTableModel()
	{
		this.varer = new ArrayList<Vare>();
	}

	public VareTableModel(ArrayList<Vare> varer)
	{
		this.varer = varer;
	}

	@Override
	public boolean isCellEditable(int row, int column)
	{
		return false;
	}

	public void setData(ArrayList<Vare> employees)
	{
		this.varer = employees;
		fireTableDataChanged();
	}

	public ArrayList<Vare> getData()
	{
		return this.varer;
	}

	@Override
	public int getColumnCount()
	{
		return 3;
	}

	@Override
	public int getRowCount()
	{
		if(this.varer == null)
		{
			return 0;
		}
		else
		{
			return this.varer.size();
		}
	}

	@Override
	public String getColumnName(int column)
	{
		String columnName = "";
		switch(column)
		{
			case 0:
				columnName = "ID";
				break;
			case 1:
				columnName = "Navn";
				break;
			case 2:
				columnName = "Pris";
				break;

		}
		return columnName;
	}

	@Override
	public Object getValueAt(int row, int column)
	{
		Object value = null;
		switch(column)
		{
			case 0:
				value = this.varer.get(row).getId();
				break;
			case 1:
				value = this.varer.get(row).getNavn();
				break;
			case 2:
				value = String.valueOf(this.varer.get(row).getSalgspris());
				break;
		}
		return value;
	}
}